package com.ryskoo.permission.aspect;

import com.ryskoo.common.constant.EurekaServiceName;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class PermissionAspect {
    private static final Logger logger = LogManager.getLogger(EurekaServiceName.PERMISSION_SERVICE);

    @Pointcut("execution(* com.ryskoo.permission.provider.controller.*.*(..))")
    public void operation() {
    }

    @Before("operation()")
    public void doBefore(JoinPoint joinPoint) {
        logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
        logger.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
    }

    @AfterReturning(returning = "result", pointcut = "operation()")
    public void doAfterReturning(Object result) {
        // 处理完请求，返回内容
        logger.info("RETURN : " + result);
    }
}
